define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'jstree', 'vue'], function ($, undefined, Backend, Table, Form, undefined, Vue) {
//读取选中的条目
    function initVue() {
        var vue = new Vue({
            el: '#form_div',
            data: {
                category1_list: [],
                category2_list: [],
                category3_list: [],
                category4_list: [],
                category5_list: [],
                category6_list: [],
                category7_list: [],
                category_id1: 0,
                category_id2: 0,
                category_id3: 0,
                category_id4: 0,
                category_id5: 0,
                category_id6: 0,
                category_id7: 0,
                name: '',
                the_latin_name: '',
                amount: 0,
                demand: 0
            },
            watch: {
                category_id1: function (val) {
                    this.category_id1 = val;
                    this.category2_list = [];
                    this.category3_list = [];
                    this.category4_list = [];
                    this.category5_list = [];
                    this.category6_list = [];
                    this.category7_list = [];
                    this.initSubCategoryList(val, 1);
                },
                category_id2: function (val) {
                    this.category_id2 = val;
                    this.category3_list = [];
                    this.category4_list = [];
                    this.category5_list = [];
                    this.category6_list = [];
                    this.category7_list = [];
                    this.initSubCategoryList(val, 2);
                },
                category_id3: function (val) {
                    this.category_id3 = val;
                    this.category4_list = [];
                    this.category5_list = [];
                    this.category6_list = [];
                    this.category7_list = [];
                    this.initSubCategoryList(val, 3);
                },
                category_id4: function (val) {
                    this.category_id4 = val;
                    this.category5_list = [];
                    this.category6_list = [];
                    this.category7_list = [];
                    this.initSubCategoryList(val, 4);
                },
                category_id5: function (val) {
                    this.category_id5 = val;
                    this.category6_list = [];
                    this.category7_list = [];
                    this.initSubCategoryList(val, 5);
                },
                category_id6: function (val) {
                    this.category_id6 = val;
                    this.category7_list = [];
                    this.initSubCategoryList(val, 6);
                }
            },
            methods: {
                initCategoryList: function () {
                    this.initSubCategoryList(0, 0);
                },
                initSubCategoryList: function (parent_id, parent_level) {
                    var data = {'parent_id': parent_id};
                    var that = this;
                    $.get('adminpublic/ajax_category_list', data, function (res) {
                        switch (parent_level) {
                            case 0:
                                that.category1_list = res;
                                break;
                            case 1:
                                that.category2_list = res;
                                break;
                            case 2:
                                that.category3_list = res;
                                break;
                            case 3:
                                that.category4_list = res;
                                break;
                            case 4:
                                that.category5_list = res;
                                break;
                            case 5:
                                that.category6_list = res;
                                break;
                            case 6:
                                that.category7_list = res;
                                break;
                        }
                    });
                }
            }
        });
        return vue;
    }
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'verify/index'
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                search: false,
                columns: [
                    [
                        {field: 'id', title: 'ID'},
                        {field: 'member_name', title: __('Member name'), searchable: false},
                        {
                            field: 'chinese_name',
                            title: __('Bacteria name'),
                            operate: 'LIKE %...%',
                            placeholder: '模糊搜索'
                        },
                        {field: 'the_latin_name', title: __('Bacteria latin name'), searchable: false},
                        {
                            field: 'type',
                            title: __('type'),
                            formatter: function (value, row, index) {
                                value = '' + value;
                                switch (value) {
                                    case '0':
                                        return __('change');
                                    case '1':
                                        return __('push');
                                }
                            },
                            searchList: {'0': __('change'), '1': __('push')},
                            style: 'min-width:100px;'
                        },
                        {
                            field: 'status',
                            title: __('Status'),
                            formatter: function (value, row, index) {
                                value = '' + value;
                                switch (value) {
                                    case '0':
                                        return __('Wait');
                                    case '1':
                                        return __('Verify passed');
                                    case '2':
                                        return __('Verify fail');
                                    default:
                                        return __('Wait');
                                }
                            },
                            searchList: {'0': __('Wait'), '1': __('Verify passed'), '2': __('Verify fail')},
                            style: 'min-width:100px;'
                        },
                        {field: 'desc', title: __('Verify desc'), searchable: false},
                        {
                            field: 'create_time',
                            title: __("Createtime"),
                            formatter: Table.api.formatter.datetime,
                            searchable: false
                        },
                        {
                            field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: __('Detail'),
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'verify/detail'
                                },
                                {
                                    name: 'verify',
                                    text: __('Verify'),
                                    icon: 'fa fa-check',
                                    classname: 'btn btn-info btn-xs btn-detail btn-dialog',
                                    url: 'verify/verify'
                                }
                            ],
                            formatter: function (value, row, index) {
                                if (row.status == '1') {
                                    return '<a href="#" class="btn btn-info btn-xs btn-success" title="审核通过"><i class="fa fa-check"></i>通过</a>';
                                } else if (row.status == '2') {
                                    return '<a href="#" class="btn btn-info btn-xs btn-warning" title="审核不通过"><i class="fa fa fa-close"></i>不通过</a>';
                                }
                                return Table.api.formatter.operate.call(this, value, row, index);
                            }
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        verify: function () {
            Form.api.bindevent($("form[role=form]"));
        },
        detail: function () {
            Form.api.bindevent($("form[role=form]"));
            var vue = initVue();
            var bacteria = Config.bacteria;
            vue.name = bacteria.chinese_name;
            vue.amount = bacteria.amount;
            vue.demand = bacteria.demand;
            vue.the_latin_name = bacteria.the_latin_name;
            vue.english_name = bacteria.english_name;
            vue.category_id1 = bacteria.category_id1;
            vue.category_id2 = bacteria.category_id2;
            vue.category_id3 = bacteria.category_id3;
            vue.category_id4 = bacteria.category_id4;
            vue.category_id5 = bacteria.category_id5;
            vue.category_id6 = bacteria.category_id6;
            vue.category_id7 = bacteria.category_id7;
            vue.initCategoryList();
        }
    };
    return Controller;
});